﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Akronus.TaskScheduler
{
    /// <summary>
    /// The implementation of <see cref="IThreadTaskRunner"/> interface which executes tasks in new threads.
    /// </summary>
    public class ThreadTaskRunner : ITaskRunner
    {
        private Thread thread = null;

        /// <summary>
        /// Executes the specified action in a new thread.
        /// </summary>
        /// <param name="action">The action.</param>
        public void Execute(ThreadStart action)
        {
            thread = new Thread(action);
            thread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            thread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
            thread.Start();
        }

        /// <summary>
        /// Aborts the task.
        /// </summary>
        public void Abort()
        {
            thread.Abort();
        }
    }
}
